<!DOCTYPE html>
<html>
<head>
    <meta charset=utf-8>
    <title>My first three.js app</title>
    <style>
        body { margin: 0; }
        canvas { width: 100%; height: 100% }
        #container{
            width:100%;
            height:650px;
            background-color: aqua;
        }
        #heading{
            width:100%;
            height:10%;
            background-color: azure;
        }
        #content-menu{
            width:20%;
            height:80%;
            background-color: chartreuse;
            float:left;
        }
        #content-body{
            width:60%;
            height:80%;
            background-color: chocolate;
            float:left;
        }
        #content-body-right{
            width:20%;
            height:80%;
            background-color: chartreuse;
            float:left;
        }
        #footer{
            width:100%;
            height:10%;
            background-color: darkgrey;
            clear: both;
        }
    </style>
</head>
<body>
<div id="container">
    <div id="heading">头部1234</div>
    <div id="content-menu">内容菜单</div>
    <div id="content-body"></div>
    <div id="content-body-right">视口右侧栏</div>
    <div id="footer">底部</div>
</div>
<script src="../js/three.js"></script>
<script src="../js/stats.min.js"></script>
<script src="../js/keys.js"></script>
<script>

    // 将所有内容都放在这个div区域内
    container = document.getElementById("content-body")

    console.log("container-area:" + container.clientWidth + "," + container.clientHeight)

    var scene = new THREE.Scene();
    var camera = new THREE.PerspectiveCamera( 75, container.clientWidth/container.clientHeight, 0.1, 1000 );

    // 显示fps值
    var stats = new Stats()
    container.appendChild(stats.dom)


    var renderer = new THREE.WebGLRenderer();
    renderer.setSize( container.clientWidth, container.clientHeight );
    container.appendChild( renderer.domElement );

    // 按键处理
    var keys = new MyKeys(camera, renderer.domElement)

    var geometry = new THREE.BoxGeometry( 1, 1, 1 );
    var material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
    var cube = new THREE.Mesh( geometry, material );
    scene.add( cube );

    camera.position.z = 5;

    var animate = function () {
        requestAnimationFrame( animate );

        cube.rotation.x += 0.01;
        cube.rotation.y += 0.01;

        // 更新显示FPS
        stats.update();

        // 显示场景内容
        renderer.render(scene, camera);
    };

    animate();


    function onWindowResize() {

        console.log("on window resize." + container.clientWidth + "," + container.clientHeight)

        camera.aspect = container.clientWidth / container.clientHeight;
        camera.updateProjectionMatrix();

        renderer.setSize( container.clientWidth, container.clientHeight );

    }
    window.addEventListener( 'resize', onWindowResize, false );

</script>
</body>
</html>